6# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import numpy as np
from skimage import data,filters
from matplotlib import pyplot as plt
#图像空间滤波函数
def corre12d(img,window):
    m=window.shape[0]
    n=window.shape[1]
    #边界通过0灰度值填充扩展
    img1=np.zeros((img.shape[0]+m-1,img.shape[1]+n-1))
    img1[(m-1)//2:(img.shape[0]+(m-1)//2),(n-1)//2:(img.shape[1]+(n-1)//2)]=img
    img2=np.zeros(img.shape)
    for i in range(img2.shape[0]):
        for j in range(img2.shape[1]):
            temp=img1[i:i+m,j:j+n]
            img2[i,j]=np.sum(np.multiply(temp,window))
            return img2
        #img为原始图像
        img=data.camera()
        window=np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]])
        img_laplace=corre12d(img,window)
        img_laplace=255*(img_laplace-img_laplace.min())/(img_laplace.max()-img_laplace.min())
        img_laplace_enhance = img + img_laplace
        img_sobel=filters.sobel(img)
        window_mean=np.ones((5,5))/(5**2)
        img_sobel_mean=corre12d(img_sobel,window_mean)
        img_mask=img_laplace_enhance*img_sobel_mean
        img_sharp_enhance=img+img_mask
        img_enhance=img_sharp_enhance**0.5
        imgList=[img,img_laplace,img_laplace_enhance,img_sobel,img_sobel_mean,img_mask,img_sharp_enhance,img_enhance]
        for grayImg in imgList:
            plt.figure()
            plt.axis('off')
            plt.imshow(grayImg,cmap='gray')
